package com.gw.quotes.net.service;

import org.ksoap2.serialization.SoapObject;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.gw.quotes.net.NewException;
import com.gw.quotes.net.Request;
import com.gw.quotes.net.Response;

/**
 * 报价厅提交报价 saveQuotation
 * 
 * @author Administrator
 *
 */
public class ProjectSaveQuotationServiceImpl extends WebBaseServiceImpl {

	@Override
	public Response setResponse() {
		return new Response();
	}
	@Override
	public void checkParam(Request request) throws NewException {
		if (request == null) {
			throw new NewException(Response.RESULT_ERROR, "传入request不能为空");
		}
		if (checkNull(request.getQutationjson())) {
			throw new NewException(Response.RESULT_ERROR, "报价错误");
		}
		if (checkNull(request.getLoginname())) {
			throw new NewException(Response.RESULT_ERROR, "用户登录名不能为空");
		}
		if (checkNull(request.getTicket())) {
			throw new NewException(Response.RESULT_ERROR, "接口凭据不能为空");
		}
	}

	@Override
	public void setParamByRequest(Request request, SoapObject rpc)
			throws NewException {
		rpc.addProperty("arg0", request.getQutationjson());
		rpc.addProperty("arg1", request.getProjecttype());
		rpc.addProperty("arg2", request.getLoginname());
		rpc.addProperty("arg3", request.getTicket());
	}

	@Override
	public String getMethodName() throws NewException {
		return "saveQuotation";
	}

	@Override
	public void resolveResponse(Object object, Response response)
			throws NewException {
		System.out.println("saveQuotationResponse:" + object.toString());
		Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss")
				.create();
		java.lang.reflect.Type type = new TypeToken<Result>() {
		}.getType();
		Result result = gson.fromJson(object.toString(), type);
		response.setMsg(result.getMsg());
		response.setResult(result.getResult());
	}
	class Result{
		/**
		 * 结果码
		 */
		private int result;

		/**
		 * 结果信息
		 */
		private String msg;

		public int getResult() {
			return result;
		}

		public void setResult(int result) {
			this.result = result;
		}

		public String getMsg() {
			return msg;
		}

		public void setMsg(String msg) {
			this.msg = msg;
		}
		
	}

}
